--[[
* 能量变更后
*]]
---@class BuffEffect71 : BaseBuffEffect
BuffEffect71 = ClientFight.CreateClass("BuffEffect71", ClientFight.BaseBuffEffect)
local t = BuffEffect71
---@param fight Fight
---@param buff FighterBuff
local BUFF_EFFECT_86_COUNT_COST_HP = "BUFF_EFFECT_86_COUNT_COST_HP";
function t:action(fight, buff, ...)
    local parameters = {...};
    local target = buff.target;
    local damage = Math.abs(parameters[2]);

    local buffEffectValue = buff.buffBean.f_BuffEffectValue;

    local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
    local currPer = (long)(damage / maxHp * Global.TEN_THOUSANDTH);

    --已累积损失生命
    local costHpPer = buff.effectParams[BUFF_EFFECT_86_COUNT_COST_HP] or 0;
    costHpPer = costHpPer + currPer;
    buff.effectParams[BUFF_EFFECT_86_COUNT_COST_HP] = costHpPer;--累计减血%% 存储下来

    local step = costHpPer / buffEffectValue[1];
    if (step < 1) then
        return IBuffEffect.FAIL;
    end
    local logCostHpPer = costHpPer;

    costHpPer = costHpPer - (step * buffEffectValue[1]);
    buff.effectParams[BUFF_EFFECT_86_COUNT_COST_HP] = costHpPer;--累计减血%% 存储下来, 把余数存起来
    local totalValue = step * buffEffectValue[2]; --计算应该增加的属性值
    clientFight.FighterManager.addEnergy(fight, buff.target, 0, 0, totalValue, EnergyChangeReasonEnum.BUFF);
    local logTotalValue = totalValue;
    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 触发每累积损失生命" .. buffEffectValue[1] .. " %% 增加 " .. buffEffectValue[2] .. " 能量 " .. " 点, 最终增加能量点: " .. logTotalValue .. " , 本次损失生命:" .. currPer .. "%% 总累计损失生命:" .. logCostHpPer .. "%%");
    return ClientFight.BaseBuffEffect.action(self, fight, buff, parameters);
end

t.New()